import Foundation

// MARK: - Recording Segment Types
enum SegmentType: String, Codable {
    case chewing = "chewing"
    case nonChewing = "no_chewing"
    case complete = "complete"
}

// MARK: - Free Recording Mode
enum FreeRecordingMode {
    case normal          // 可在咀嚼/非咀嚼之间切换
    case nonChewingOnly  // 仅记录非咀嚼，不提供切换
}

// MARK: - Recording Segment
struct RecordingSegment: Identifiable, Codable {
    let id: UUID
    let type: SegmentType
    let startDate: Date
    let endDate: Date
    let rawSamples: [RawSample]
    
    var duration: Double {
        endDate.timeIntervalSince(startDate)
    }
    
    init(type: SegmentType, startDate: Date, endDate: Date, rawSamples: [RawSample]) {
        self.id = UUID()
        self.type = type
        self.startDate = startDate
        self.endDate = endDate
        self.rawSamples = rawSamples
    }
}

// MARK: - Free Recording Session
struct FreeRecordingSession: Identifiable {
    let id: UUID
    let sessionUUID: String  // 用于标识同一组数据
    let startDate: Date
    var endDate: Date?
    var segments: [RecordingSegment]
    var note: String?
    
    var totalDuration: Double {
        guard let end = endDate else { return 0 }
        return end.timeIntervalSince(startDate)
    }
    
    var chewingSegments: [RecordingSegment] {
        segments.filter { $0.type == .chewing }
    }
    
    var nonChewingSegments: [RecordingSegment] {
        segments.filter { $0.type == .nonChewing }
    }
    
    init() {
        self.id = UUID()
        self.sessionUUID = UUID().uuidString
        self.startDate = Date()
        self.segments = []
    }
}

// MARK: - Upload Item (for serial upload)
struct UploadItem {
    let fileURL: URL
    let objectKey: String
    let segmentType: SegmentType
    let timestamp: Date
    let segmentIndex: Int
}
